package kr.hkit.androidcomplete01.ch07;

import kr.hkit.androidcomplete01.ch07.DrawText.MyView;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;

public class TypeFaceAndCustomFont extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(new MyView(this));
	}

	class MyView extends View {
		
		private Paint paint;
		private int y = 1;
		private Typeface mFont;
		private String str;
		
		public MyView(Context context) {
			super(context);
			paint = new Paint(Paint.ANTI_ALIAS_FLAG);
			mFont = Typeface.createFromAsset(getAssets(), "comic.ttf");
			str = "Custom Font Test";
		}
		
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
	
			canvas.drawColor(Color.LTGRAY);
			
			//316페이지 TypeFace
			paint.setTextSize(30);
			paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
			canvas.drawText("Font:Default", 10, y++ * 40, paint);
			
			paint.setTypeface(Typeface.create(Typeface.DEFAULT_BOLD, Typeface.NORMAL));
			canvas.drawText("Font:Default Bold", 10, y++ * 40, paint);
			
			paint.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL));
			canvas.drawText("Font:Monospace", 10, y++ * 40, paint);
			
			paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL));
			canvas.drawText("Font:Sans Serif", 10, y++ * 40, paint);
			
			paint.setTypeface(Typeface.create(Typeface.SERIF, Typeface.NORMAL));
			canvas.drawText("Font:Serif", 10, y++ * 40, paint);
			
			
			//317페이지 CustomFont
			paint.setAntiAlias(true);
			paint.setTypeface(mFont);
			paint.setTextSize(30);
			canvas.drawText(str, 10, y++ * 40, paint);
		}
	}
}
